<template>
  <a-card :bordered="false">

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-row>
        <a-col :span="2">
      <#if (formColumns?size) gt 2 >
          <a-dropdown v-model="visible" style="text-align: left;">
            <a class="ant-dropdown-link" @click="e => e.preventDefault()">
              搜索条件<a-icon type="down"/>
            </a>
            <a-menu slot="overlay" @click="handleMenuClick">
              <#-- 动态长度  -->
              <#list 3..(formColumns?size)!3 as i>
                  <a-menu-item key="${formColumns[i-1].fieldName}Check">
                    <a-checkbox :checked="${formColumns[i-1].fieldName}Show"></a-checkbox>${formColumns[i-1].uiFieldcomment}</a-menu-item>
              </#list>
            </a-menu>
          </a-dropdown>
      </#if>
        </a-col>
        <a-col :span="22" class="ant-table-right">
          <a-button type="primary" @click="handleAdd" shape="circle" icon="plus"></a-button>
          <a-button class="ant-ui-noborder" icon="bar-chart" @click="handleExportXls('用户信息')">导出</a-button>
          <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
            <a-button class="ant-ui-noborder" icon="folder-open">导入</a-button>
          </a-upload>
          <a-dropdown v-if="selectedRowKeys.length > 0">
            <a-menu slot="overlay">
              <a-menu-item key="1" @click="batchDel">
                <a-icon type="delete"/>删除</a-menu-item>
            </a-menu>
            <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down"/> </a-button>
          </a-dropdown>
        </a-col>
      </a-row>
    </div>

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <#if (formColumns?size) gt 2 >
          <#list 0..1 as i>
            <a-col :md="6" :sm="8">
              <a-form-item label="${formColumns[i].uiFieldcomment}">
<#--                <a-input placeholder="请输入${formColumns[i].uiFieldcomment}" v-model="queryParam.${formColumns[i].fieldName}"></a-input>-->
                <#if formColumns[i].uiUitype =='2'>
                  <a-date-picker style="width: 100%" showTime  v-model="queryParam.${formColumns[i].fieldName}" />
                <#elseif formColumns[i].uiUitype =='1'|| formColumns[i].uiUitype =='6'>
                  <j-dict-select-tag  v-model="queryParam.${formColumns[i].fieldName}"  dictCode="${formColumns[i].uiSelectfunc}">
                  </j-dict-select-tag>
                <#elseif formColumns[i].uiUitype =='4'>
                  <a-input-number style="width: 100%" v-model="queryParam.${formColumns[i].fieldName}" />
                <#else>
                  <a-input v-model="queryParam.${formColumns[i].fieldName}"/>
                </#if>
              </a-form-item>
            </a-col>
          </#list>
          <#-- 动态长度  -->
          <#list 3..(formColumns?size)!3 as i>
            <a-col :md="6" :sm="8" v-show="${formColumns[i-1].fieldName}Show">
              <a-form-item label="${formColumns[i-1].uiFieldcomment}">
<#--                <a-input placeholder="请输入${formColumns[i-1].uiFieldcomment}" v-model="queryParam.${formColumns[i-1].fieldName}"></a-input>-->
                <#if formColumns[i-1].uiUitype =='2'>
                  <a-date-picker style="width: 100%" showTime  v-model="queryParam.${formColumns[i-1].fieldName}" />
                <#elseif formColumns[i-1].uiUitype =='1'|| formColumns[i].uiUitype =='6'>
                  <j-dict-select-tag v-model="queryParam.${formColumns[i-1].fieldName}"  dictCode="${formColumns[i-1].uiSelectfunc}">
                  </j-dict-select-tag>
                <#elseif formColumns[i-1].uiUitype =='4'>
                  <a-input-number style="width: 100%" v-model="queryParam.${formColumns[i-1].fieldName}" />
                <#else>
                  <a-input v-model="queryParam.${formColumns[i-1].fieldName}"/>
                </#if>
              </a-form-item>
            </a-col>
          </#list>
          <#else>
            <#list formColumns as po>
            <a-col :md="6" :sm="8">
            <a-form-item label="${po.uiFieldcomment}">
<#--              <a-input placeholder="请输入${po.uiFieldcomment}" v-model="queryParam.${po.fieldName}"></a-input>-->
              <#if po.uiUitype =='2'>
                <a-date-picker style="width: 100%" showTime  v-model="queryParam.${po.fieldName}" />
              <#elseif po.uiUitype =='1'|| po.uiUitype =='6'>
                <j-dict-select-tag  v-model="queryParam.${po.fieldName}"  dictCode="${po.uiSelectfunc}">
                </j-dict-select-tag>
              <#elseif po.uiUitype =='4'>
                <a-input-number style="width: 100%" v-model="queryParam.${po.fieldName}" />
              <#else>
                <a-input v-model="queryParam.${po.fieldName}"/>
              </#if>
            </a-form-item>
           </a-col>
            </#list>

          </#if>

<#--<#list originalColumns as po>
<#if po.uiAppview =='true' >
          <a-col :md="6" :sm="8">
            <a-form-item label="${po.uiFieldcomment}">
              <a-input placeholder="请输入${po.uiFieldcomment}" v-model="queryParam.${po.fieldName}"></a-input>
            </a-form-item>
          </a-col>
</#if>
</#list>-->
        <#--  <template v-if="toggleSearchStatus">

          </template>-->
          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button  shape="circle" @click="searchQuery" icon="search"></a-button>
              <a @click="searchReset" icon="reload" style="margin-left: 8px">重置</a>
              <#--<a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>-->
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <${entityName?uncap_first}-modal ref="modalForm" @ok="modalFormOk"></${entityName?uncap_first}-modal>
  </a-card>
</template>

<script>
  import ${entityName}Modal from './modules/${entityName}Modal'
  import { HjListMixin } from '@/mixins/HjListMixin'
  import {initDictOptions, filterDictText} from '@/components/dict/JDictSelectUtil'
  import { httpAction,getAction,postAction } from '@/api/manage'


  export default {
    name: "${entityName}List",
    mixins:[HjListMixin],
    components: {
      ${entityName}Modal
    },
    data () {
      return {
        description: '管理页面',


<#if (formColumns?size) gt 2 >
        visible:false,
        //搜索条件控制显隐
        <#list 3..(formColumns?size)!3 as i>
        ${formColumns[i-1].fieldName}Show:false,
        </#list>
</#if>


        <#list originalColumns as po>
        <#if (po.uiUitype=='1' ||po.uiUitype=='6') &&  po.uiSelectfunc!=''>
        //字典值-${po.uiFieldcomment}
        ${po.fieldName}DictOptions:[],
        </#if>
        </#list>

        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
           },
          <#list originalColumns as po>
           <#if po.uiApplist =='true'>
		   {
            title: '${po.uiFieldcomment}',
            align:"center",
            dataIndex: '${po.fieldName}',
             <#if (po.uiUitype=='1' ||po.uiUitype=='6') &&  po.uiSelectfunc!=''>
             customRender: (text, record, index) => {
             //字典值替换通用方法
             return filterDictText(this.${po.fieldName}DictOptions, text);
            }
             </#if>
           },
		   </#if>
		  </#list>
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
		url: {
          list: "/${entityName?uncap_first}/list",
          delete: "/${entityName?uncap_first}/delete",
          deleteBatch: "/${entityName?uncap_first}/deleteBatch",
          exportXlsUrl: "${entityName?uncap_first}/exportXls",
          importExcelUrl: "${entityName?uncap_first}/importExcel",
       },
    }
  },
  computed: {
    importExcelUrl: function(){
      <#noparse>return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;</#noparse>
    }
  },
    methods: {


      initDictConfig() {
        <#list originalColumns as po>
        <#if (po.uiUitype=='1' ||po.uiUitype=='6') &&  po.uiSelectfunc!=''>
        //初始化字典-${po.uiFieldcomment}
        initDictOptions('${po.uiSelectfunc}').then((res) => {
          if(res.success){
            this.${po.fieldName}DictOptions = res.result;
          }
      })
        </#if>
        </#list>
      },
      <#if (formColumns?size) gt 2 >
        handleMenuClick(e) {
          <#list 3..(formColumns?size)!3 as i>
          if (e.key === '${formColumns[i-1].fieldName}Check') {
            this.${formColumns[i-1].fieldName}Show = !this.${formColumns[i-1].fieldName}Show
          }
          </#list>
        },
      </#if>

    }
  }

</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>